<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<head>
    <title>修改密码</title>

</head>


<div class="container bs-sidenav">
    <div class="row">
        <div class="col-sm-10">
            <ol class="breadcrumb">
                <li><a href="${ctx}/workbench/profile">我的资料</a></li>
                <li class="active">修改密码</li>
            </ol>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-10">
        <c:if test="${failed=='failed'}">
            <div class="alert alert-danger">
                修改密码失败
            </div>
        </c:if>
        <c:if test="${success=='success'}">
            <div class="alert alert-success">
                修改密码成功
            </div>
        </c:if>
            </div>
    </div>

    <div class="row">
        <div class="col-sm-10">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="panel-title">修改密码</div>
                </div>
                <div class="panel-body">

                    <div class="row">
                        <sf:form id="idChangePwdForm" class="form-horizontal"
                                 action="${ctx}/workbench/profile/changepwd" method="post">



                            <div class="form-group">
                                <label class="control-label col-sm-2">旧密码:</label>

                                <div class=" col-sm-3">
                                    <input name="oldPwd" type="text" class="form-control">
                                    <div id="idOldPwdError" class="help-block with-errors">
                                        <c:if test="${failed=='failed' && oldPwdErr!=null}">
                                            <div class="alert alert-danger">
                                                    ${oldPwdErr}
                                            </div>
                                        </c:if>
                                    </div>
                                </div>

                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">新密码:</label>

                                <div class=" col-sm-3">
                                    <input name="newPwd" type="text" class="form-control">
                                    <div id="idNewPwdError" class="help-block with-errors">
                                        <c:if test="${failed=='failed' && newPwdErr!=null}">

                                            <div class="alert alert-danger">
                                                    ${newPwdErr}
                                            </div>
                                        </c:if>
                                    </div>
                                </div>

                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">确认密码:</label>

                                <div class=" col-sm-3">
                                    <input name="confirmPwd" type="text" class="form-control">
                                    <div id="idConfirmPwdError" class="help-block with-errors">

                                    </div>
                                </div>

                            </div>

                            <div class="col-sm-offset-2">
                                <button type="submit" class="btn btn-warning">提交</button>
                            </div>
                        </sf:form>

                    </div>
                </div>
            </div>
        </div>

    </div>

</div>
<script type="application/javascript">
    $(function(){

        $("#myprofile-chgPwd-tag").addClass("active");
        $("#idChangePwdForm").submit(function (e) {
            var oldPwd =  $(this).find("input[name='oldPwd']").val();
            var newPwd = $(this).find("input[name='newPwd']").val();
            var confirmPwd = $(this).find("input[name='confirmPwd']").val();
            $('#idOldPwdError').empty();
            $('#idNewPwdError').empty();
            $('#idConfirmPwdError').empty();

            if(oldPwd =="" || oldPwd == NaN || oldPwd == undefined){
                e.preventDefault();
                $('#idOldPwdError').html("<div class='alert alert-danger'>旧密码不能为空</div>");
                return;
            }
            if(newPwd =="" || newPwd == NaN || newPwd == undefined){
                e.preventDefault();
                $('#idNewPwdError').html("<div class='alert alert-danger'>新密码不能为空</div>");
                return;
            }
            if (newPwd != confirmPwd) {
                e.preventDefault();
                $('#idConfirmPwdError').html("<div class='alert alert-danger'>两次输入的密码不一致</div>");
                return;
            }

        });

    })

</script>
